Date Property subtraction bug
Reported by Rick DeNatale | May 19th, 2009 @ 12:43 PM | in 0.0.8
Reported by Paul Scott-Murphy
I saw the following stack trace just now when testing an
iCalendar
file.
TypeError: expected numeric or date
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/
ruby/1.8/date.rb:1220:in -'<br/>
from /Users/paulsm/Projects/ri_cal/lib/ri_cal/property_value/date.rb:
120:in send'<br/>
from /Users/paulsm/Projects/ri_cal/lib/ri_cal/property_value/date.rb:
120:in method_missing'<br/>
from /Users/paulsm/Projects/ri_cal/lib/ri_cal/
occurrence_enumerator.rb:163:in
set_occurrence_properties!'<br/>
from /Users/paulsm/Projects/ri_cal/lib/ri_cal/
occurrence_enumerator.rb:171:in
recurrence'<br/>
from /Users/paulsm/Projects/ri_cal/lib/ri_cal/
occurrence_enumerator.rb:105:in
each'<br/>
from /Users/paulsm/Projects/ri_cal/lib/ri_cal/
occurrence_enumerator.rb:118:in
to_a'<br/>
from /Users/paulsm/Projects/ri_cal/lib/ri_cal/
occurrence_enumerator.rb:118:in
to_a'<br/>
from /Users/paulsm/Projects/ri_cal/lib/ri_cal/
occurrence_enumerator.rb:137:in
occurrences'<br/>
from (irb):27
from (irb):26:in `each'
from (irb):26
from :0
It looks like the use of method_missing in
RiCal::PropertyValue::Date
isn't correct when invoking the - method, as the ::Date class
requires
the argument sent to that method to be a ::Numeric or ::Date.
I added the following test for this in date_spec.rb:
describe ".-" do
it "should return duration for two instances" do
dt1 = RiCal::PropertyValue::Date.new(nil, :value =>
DateTime.parse("20090519"))
dt2 = RiCal::PropertyValue::Date.new(nil, :value =>
DateTime.parse("20090518"))
(dt1 - dt2).should == 1
end
end
And made the test pass with this additional method in
RiCal::PropertyValue::Date
def - (x)
self.ruby_value - x.ruby_value
end
There may be other instances of using the - or + methods on
RiCal::PropertyValue classes elsewhere too, which I haven't looked
at.
Comments and changes to this ticket
-
Rick DeNatale May 19th, 2009 @ 12:43 PM
I replied:
Thanks Paul.Although there is a bug here. I'm not sure that the fix is correct,
although I haven't had my coffee yet this morning.I'm pretty sure that subtracting two PropertyValue::Dates should
result in a PropertyValue::Duration rather than an Integer.Could you send me the icalendar file which caused the failure?
-
Rick DeNatale May 19th, 2009 @ 12:44 PM
Paul later added:
Having read through how the DateTime class handles this, I'm not sure
that the fix is quite right now. That said, there's still a bug.--Paul
-
Rick DeNatale May 19th, 2009 @ 04:18 PM
Okay,
date - date will now produce a duration
date - datetime will also produce a duration
date - duration will produce a datetime
date + duration will produce a datetime -
Rick DeNatale May 19th, 2009 @ 04:28 PM
- State changed from new to resolved
- Milestone set to 0.0.8
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป
A new icalendar data (RFC 2445) gem for Ruby which supports time zones and enumeration of occurrences